package orgs.example.mapper;

import org.apache.ibatis.annotations.*;
import orgs.example.pojo.MeetingRoom;
import orgs.example.pojo.User;

import java.util.List;

@Mapper
public interface AdminMapper {

//    添加房间
    @Insert("INSERT INTO meeting_room  " +
            "VALUES (null,#{roomName}, #{roomType}, #{roomSquare}, #{roomCapacity}, #{roomProjector}, " +
            "#{roomAudio}, #{roomNetwork}, #{roomPrice}, #{roomStatus})")
    void addMeetingRoom(MeetingRoom meetingRoom);


//  更改房间
    @Update("<script>" +
            "UPDATE meeting_room " +
            "<set>" +
            "<if test='roomName != null'>room_name = #{roomName},</if>" +
            "<if test='roomType != null'>room_type = #{roomType},</if>" +
            "<if test='roomSquare != null'>room_square = #{roomSquare},</if>" +
            "<if test='roomCapacity != null'>room_capacity = #{roomCapacity},</if>" +
            "<if test='roomProjector != null'>room_projector = #{roomProjector},</if>" +
            "<if test='roomAudio != null'>room_audio = #{roomAudio},</if>" +
            "<if test='roomNetwork != null'>room_network = #{roomNetwork},</if>" +
            "<if test='roomPrice != null'>room_price = #{roomPrice},</if>" +
            "<if test='roomStatus != null'>room_status = #{roomStatus},</if>" +
            "</set>" +
            "WHERE room_id = #{roomId}" +
            "</script>")
    void changeMeetingroom(MeetingRoom meetingRoom);


//    删除房间
    @Delete("delete from meeting_room where room_id = #{roomid}")
    void deleteroom(Integer roomid);

//  更改用户状态
    @Update("update user set user_status=#{userStatus} where user_id=#{userId}")
    void changeUserStatus(Integer userId, String userStatus);

//    删除用户
    @Delete("delete from user where user_id=#{userId}")
    void deleteuser(Integer userId);

//    根据条件找用户
    @Select("<script>" +
            "SELECT * FROM user " +
            "<where>" +
            "   <if test='userRole != null'>" +
            "       AND user_role = #{userRole}" +
            "   </if>" +
            "   <if test='userStatus != null'>" +
            "       AND user_status= #{userStatus}" +
            "   </if>" +
            "</where>" +
            "</script>")
    List<User> searchUser(User user);

//    根据条件找房间
@Select("<script>" +
        "SELECT *" +
        "FROM meeting_room " +
        "<where>" +
        "  <if test='roomName != null and roomName != \"\"'>" +
        "    AND room_name = #{roomName}" +
        "  </if>" +
        "  <if test='roomType != null and roomType != \"\"'>" +
        "    AND room_type = #{roomType}" +
        "  </if>" +
        "  <if test='roomSquare != null'>" +
        "    AND room_square = #{roomSquare}" +
        "  </if>" +
        "  <if test='roomCapacity != null'>" +
        "    AND room_capacity = #{roomCapacity}" +
        "  </if>" +
        "  <if test='roomProjector != null'>" +
        "    AND room_projector = #{roomProjector}" +
        "  </if>" +
        "  <if test='roomAudio != null'>" +
        "    AND room_audio = #{roomAudio}" +
        "  </if>" +
        "  <if test='roomNetwork != null'>" +
        "    AND room_network = #{roomNetwork}" +
        "  </if>" +
        "  <if test='roomPrice != null'>" +
        "    AND room_price = #{roomPrice}" +
        "  </if>" +
        "  <if test='roomStatus != null and roomStatus != \"\"'>" +
        "    AND room_status = #{roomStatus}" +
        "  </if>" +
        "</where>" +
        "</script>")
    List<MeetingRoom> searchMeetingRoom(MeetingRoom meetingRoom);

//  根据用户id删除订单表
    @Delete("delete from reservation where user_id = #{userId}")
    void deleteReservaionByUserId(Integer userId);

//  根据订单号删除退订订单
    @Delete("delete from cancellation where reserve_id=#{reserveId}")
    void deleteCancellationByReserveId(Integer reserveId);
}
